Organizing a Go module
https://go.dev/doc/modules/layout
最もシンプルなパッケージ
project-root-directory/
go.mod
modname.go
modname_test.go
コマンドラインツールの場合
project-root-directory/
go.mod
auth.go
auth_test.go
client.go
main.go
main.go に main 関数を置くことになる
Package or command with supporting packages
パッケージに分ける場合は、 internal というディレクトリを作るのを推奨
これは今までの standard のやつと同じっぽい
外に公開するべきものと区別するため
Multiple packages
外から使えるものを階層に分けたい場合はこんな感じで分ける
外から使われたくないものは internal に
project-root-directory/
go.mod
modname.go
modname_test.go
auth/
auth.go
auth_test.go
token/
token.go
token_test.go
hash/
hash.go
internal/
trace/
trace.go
Multiple commands
project-root-directory/
go.mod
internal/
... shared internal packages
prog1/
main.go
prog2/
main.go
Packages and commands in the same repository
project-root-directory/
go.mod
modname.go
modname_test.go
auth/
auth.go
auth_test.go
internal/
... internal packages
cmd/
prog1/
main.go
prog2/
main.go
Server project(これが一番良く使いそう)
project-root-directory/
go.mod
internal/
auth/
...
metrics/
...
model/
...
cmd/
api-server/
main.go
metrics-analyzer/
main.go
結論、結局元のやつとあんま変わんないのでは...